<style>
    .pay-qrcode{
        padding-left: 40px;
    }
</style>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">我的钱包</div>
                </div>
                <div class="widget-body am-form tpl-form-line-form">
                    <div class="am-form-group">
                        <label class="am-u-sm-3 am-u-lg-2 am-form-label"> 现有余额 </label>
                        <div class="am-u-sm-3 am-u-end tpl-form-text"> {$money} </div>
                    </div>
                    <div class="am-form-group">
                        <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 充值金额 </label>
                        <div class="am-u-sm-3 am-u-end">
                            <input id="money" type="number" min="1" class="tpl-form-input" name="data[money]" value="" required>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                            <button id="recharge" type="button" class="am-btn am-btn-secondary">生成充值二维码
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="money/recharge" /}
<script src="/assets/plugins/qrcode/qrcode.min.js"></script>
<script>
    $(function () {
        $('#recharge').on('click', function () {
            var money = document.getElementById('money');
            if(!money.value || money.value == 0){
                $.show_error('填写要充值的金额');
                return false;
            }
            $.get("{:url('money/recharge')}", {
                money:money.value
            },function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
                $.showAction({
                    title: '在线充值', 
                    area: '400px', 
                    content: template('tpl-recharge', result.data), 
                    uCheck: true, 
                    btn: ['取消'],
                    success: function ($content) {
                        new QRCode(document.getElementById("qrcode"), result.data.code_url);
                        //检测支付状态
                        var interval = setInterval(function(){
                            $.post("{:url('money/ok')}",{
                                order_no:result.data.order_no
                            },function(res){
                                if(res.code == 1){
                                    window.location.reload();
                                }
                            });
                        },3000);
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
    });
</script>
